<!DOCTYPE html>
<!--
  Copyright 2011 Google Inc. All Rights Reserved.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS-IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

-->
<html><head>
<title>tv.ui.Document</title>
<script type="text/javascript" src="../testbase.js"></script>
<script type="text/javascript">
  goog.require('goog.dom');
  goog.require('goog.testing.StrictMock');
  goog.require('tv.ui.Component');
  goog.require('tv.ui.Document');
</script>
</head>
<body>

<div id="decorateme"></div>

<script type="text/javascript">

  // Tests if second attempt to decorate() is successful.
  function testGetInstance() {
    assertEquals("getInstance() should return the same instace on each call",
        tv.ui.Document.getInstance(),
        tv.ui.Document.getInstance());
  }

  // Testing calling focus() and blur() on component.
  function testBlurFocusKeyEvents() {
    var event = new goog.events.KeyEvent(goog.events.KeyCodes.DOWN, 0, false, null);
    var mock = new goog.testing.StrictMock(tv.ui.Component);
    mock.getParent();
    mock.dispatchFocus_();
    mock.dispatchKey_(event);
    mock.getParent();
    mock.dispatchBlur_();
    mock.$replay();

    tv.ui.Document.getInstance().onKey(event);
    tv.ui.Document.getInstance().setFocusedComponent(mock);
    tv.ui.Document.getInstance().onKey(event);
    tv.ui.Document.getInstance().setFocusedComponent(null);

    mock.$verify();
  }

</script>
</body></html>
